#include <stx/test/core_macro_test.cpp>
#include <stx/test/core_inc_test.cpp>
#include <stx/test/core_concepts_test.cpp>
#include <stx/test/core_lambda_test.cpp>
#include <stx/test/core_libx_test.cpp>
#include <stx/test/core_stx_test.cpp>
#include <stx/test/core_time_test.cpp>
#include <stx/test/core_random_test.cpp>
#include <stx/test/core_algo_test.cpp>
#include <stx/test/core_fs_test.cpp>
#include <stx/test/core_encoding_test.cpp>
#include <stx/test/core_misc_test.cpp>
#include <stx/test/core_regex_test.cpp>
#include <stx/test/core_json_test.cpp>
#include <stx/test/core_posix_test.cpp>
#include <stx/test/core_net_test.cpp>
#include <stx/test/core_shell_test.cpp>
#include <stx/test/core_http_test.cpp>

int main()
{
    try
    {
        gLogLevel()           = 1;
        gCopyLogsToTerminal() = true;
        initPosixEnv();

        schedule(
            []
            {
                auto test_cases = gTestCases__().visit(
                    [](auto& test_cases)
                    { return std::exchange(test_cases, {}); });

                xout(Tco::K_GREEN,
                     "Run "sv,
                     test_cases.size(),
                     " test cases ..."sv,
                     Tco::K_RESET);
                ranges::for_each(test_cases, BIND(std::invoke, _1));
                xout(Tco::K_GREEN,
                     "Test is finished successfully."sv,
                     Tco::K_RESET);
                std::quick_exit(EXIT_SUCCESS);
            });

        startEventLoop();
    }
    catch (std::exception const& e)
    {
        xout(Tco::K_RED,
             "Test is failed with error: "sv,
             e.what(),
             Tco::K_RESET);
    }
    catch (...)
    {
        xout(Tco::K_RED, "Test is failed with unknown errors."sv, Tco::K_RESET);
    }

    xout(Tco::K_RED, "Test is finished with errors."sv, Tco::K_RESET);
    return EXIT_FAILURE;
}